package controller;

import dao.Roleline_lxDao;
import entity.Roleline_lx;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import service.Roleline_lxService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/roleline")
@Scope("prototype")
public class Roleline_lxController {

    @Resource(name = "roleline_lxService")
    private Roleline_lxService roleline_lxService;
    @Resource(name = "roleline_lxDao")
    private Roleline_lxDao roleline_lxDao;
    @RequestMapping("/queryConditionPage")
    @ResponseBody
    public Map<String,Object> queryConditionPage(Roleline_lx lx, @RequestParam(value = "pageNumber",defaultValue = "1",required = false) int pageNumber, @RequestParam(value = "pageSize",defaultValue = "5",required = false) int pageSize){
        Map<String,Object> map = new HashMap<String,Object>() ;

        map.put("total",roleline_lxDao.getCount(lx)) ;
        System.out.println(lx.getXlid());
        map.put("rows",roleline_lxService.query(lx.getXlid(),lx.getRunningstate(),pageSize,pageNumber)) ;
        return map ;
    }
    @RequestMapping("/saveRole")
    @ResponseBody
    public Map<String,Object> save(Roleline_lx roleline_lx,HttpServletRequest requset, @RequestParam(value = "pageNumber",defaultValue = "1",required = false) int pageNumber, @RequestParam(value = "pageSize",defaultValue = "5",required = false) int pageSize) {
        HttpSession session = requset.getSession();
        Date d = new Date();
        String xlid  = requset.getParameter("xzxlid");
        System.out.println(xlid);
        String xlname =requset.getParameter("xzxlname");
        System.out.println(xlname);
        String qsganhao = requset.getParameter("qsganhao");
        System.out.println(qsganhao);
        String zzganhao = requset.getParameter("zzganhao");
        System.out.println(zzganhao);
        int tajishu = Integer.parseInt(requset.getParameter("tajishu"));
        System.out.println(tajishu);
      String remark = requset.getParameter("remark");
        System.out.println(remark);
        int startstate = Integer.parseInt(requset.getParameter("startstate"));
        System.out.println(startstate);
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
       String creationDate=sdf.format(new Date());
       System.out.print(creationDate);
        roleline_lx.setXlid(xlid);
        roleline_lx.setXlname(xlname);
        roleline_lx.setQsganhao(qsganhao);
        roleline_lx.setZzganhao(zzganhao);
        roleline_lx.setTajishu(tajishu);
        roleline_lx.setStartstate(startstate);
        roleline_lx.setCreationDate(creationDate);
        roleline_lx.setRemark(remark);
        roleline_lxService.add(roleline_lx);
        Roleline_lx lx = new Roleline_lx();
        lx.setRunningstate(-1);
        Map<String,Object> map = new HashMap<String,Object>() ;
        map.put("total",roleline_lxDao.getCount(lx)) ;
        System.out.println( map.put("total",roleline_lxDao.getCount(lx)));
        map.put("rows",roleline_lxService.query(null,-1,pageSize,pageNumber)) ;
        return map;
    }
    @RequestMapping("/updateRole")
    @ResponseBody
    public Map<String,Object> update(Roleline_lx roleline_lx,HttpServletRequest requset,@RequestParam(value = "pageNumber",defaultValue = "1",required = false) int pageNumber, @RequestParam(value = "pageSize",defaultValue = "5",required = false) int pageSize) {
        HttpSession session = requset.getSession();
        String xlid  = requset.getParameter("xgxlid");
        System.out.println(xlid);
        String xlname =requset.getParameter("xgxlname");
        System.out.println(xlname);
        String qsganhao = requset.getParameter("xgqsganhao");
        System.out.println(qsganhao);
        String zzganhao = requset.getParameter("xgzzganhao");
        System.out.println(zzganhao);
        int tajishu = Integer.parseInt(requset.getParameter("xgtajishu"));
        System.out.println(tajishu);
        String remark = requset.getParameter("xgremark");
        System.out.println(remark);
        int startstate = Integer.parseInt(requset.getParameter("startstate"));
        System.out.println(startstate);
        String creationDate =requset.getParameter("xgcreationDate");
        System.out.print(creationDate);
        roleline_lx.setXlid(xlid);
        roleline_lx.setXlname(xlname);
        roleline_lx.setQsganhao(qsganhao);
        roleline_lx.setZzganhao(zzganhao);
        roleline_lx.setTajishu(tajishu);
        roleline_lx.setStartstate(startstate);
        roleline_lx.setCreationDate(creationDate);
        roleline_lx.setRemark(remark);
        roleline_lxService.upd(roleline_lx);
       Roleline_lx lx = new Roleline_lx();
       lx.setRunningstate(-1);
       Map<String,Object> map = new HashMap<String,Object>() ;
       map.put("total",roleline_lxDao.getCount(lx)) ;
       System.out.println( map.put("total",roleline_lxDao.getCount(lx)));
       map.put("rows",roleline_lxService.query(null,-1,pageSize,pageNumber)) ;
       return map;
    }
    @RequestMapping("/deleteRole")
    @ResponseBody
    public Map<String,Object> delete(int id,HttpServletRequest requset, @RequestParam(value = "pageNumber",defaultValue = "1",required = false) int pageNumber, @RequestParam(value = "pageSize",defaultValue = "5",required = false) int pageSize) {

         id = Integer.parseInt(requset.getParameter("id"));
         roleline_lxService.del(id);
        Roleline_lx lx = new Roleline_lx();
       lx.setRunningstate(-1);
        Map<String,Object> map = new HashMap<String,Object>() ;
        map.put("total",roleline_lxDao.getCount(lx)) ;
        map.put("rows",roleline_lxService.query(null,-1,pageSize,pageNumber)) ;
        return map;
    }
    @RequestMapping("/oneRole")
    @ResponseBody
    public Roleline_lx oneRole(int id){

        return roleline_lxService.one(id);
        }

   @RequestMapping("/savetwo")
   @ResponseBody
   public  String sava(Roleline_lx  roleline_lx,HttpServletRequest request){
       HttpSession session = request.getSession();
       Date d = new Date();
       String xlid  = request.getParameter("xzxlid");
       System.out.println(xlid);
       String xlname =request.getParameter("xzxlname");
       System.out.println(xlname);
       String qsganhao = request.getParameter("qsganhao");
       System.out.println(qsganhao);
       String zzganhao = request.getParameter("zzganhao");
       System.out.println(zzganhao);
       int tajishu = Integer.parseInt(request.getParameter("tajishu"));
       System.out.println(tajishu);
       String remark = request.getParameter("remark");
       System.out.println(remark);
       int startstate = Integer.parseInt(request.getParameter("startstate"));
       System.out.println(startstate);
      String time = request.getParameter("time");
       System.out.print(time);
       roleline_lx.setXlid(xlid);
       roleline_lx.setXlname(xlname);
       roleline_lx.setQsganhao(qsganhao);
       roleline_lx.setZzganhao(zzganhao);
       roleline_lx.setTajishu(tajishu);
       roleline_lx.setStartstate(startstate);
       roleline_lx.setCreationDate(time);
       roleline_lx.setRemark(remark);
       roleline_lxService.add(roleline_lx);
       return "redirect:/roleline/queryConditionPage";
   }
}
